package API.Collection.BasicMethods.Contains;

public class StudentsOverrideEquals {
    private String name;
    private int age;
    private String gender;

    public StudentsOverrideEquals() {
    }

    public StudentsOverrideEquals(String name, int age, String gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Override
    public String toString() {
        return "StudentsOverrideEquals{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                '}';
    }

    @Override
    // 这里重写了equals方法，通过对比相应类型中的相应数据来判断是否相同
    public boolean equals(Object o) {
        if(o instanceof StudentsOverrideEquals students) {
            if(students.getName().equals(name) && students.getAge() == age && students.getGender().equals(gender)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
